import * as types from '../action-typess';
export default function reducer(state={
  list: [],
  fetched: false,
  cateList: [],
  sort : '',
  searchValue : '',
  page : 1
}, action) {
  //判断类型做出对应state的改变
  switch (action.type){
    // 首页
    case types.FETCH_CATEGORY: {
      return {...state, fetching: true}
    }
    case types.FETCH_CATEGORY_FULFILLED: {
      if(action.payload){
        return {
          ...state,
          fetching: false,
          fetched: true,
          list: action.payload.list,
        }
      }
    }
    // 分类列表
    case types.FETCH_CATELIST: {
      return {...state, fetching: true}
    }
    case types.FETCH_CATELIST_FULFILLED: {
      if(action.payload){
        return {
          ...state,
          fetching: false,
          fetched: true,
          cateList: [...state.cateList,...action.payload.goods_list],
          page : state.page + 1,
          sort : action.payload.sort,
          searchValue : action.payload.searchValue
        }
      }
    }
    // 9.9
    case types.FETCH_NINE: {
      return {...state, fetching: true}
    }
    case types.FETCH_NINE_FULFILLED: {
      if(action.payload){
        return {
        ...state,
        fetching: false,
        fetched: true,
        cateList: action.payload.goods_list,
        }
      }
    }
  }
  return state;
}